<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String text = new String(request.getParameter("findmessage").getBytes("ISO8859_1"),"UTF-8");
if(text==null){
    text="";
}
session.setAttribute("findmessage",text);
String usernumber = (String)session.getAttribute("username");
%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>留言簿 - 同学录 </title>
    
	<meta name="title" content="留言簿 - 同学录" >
	<meta name="description" content="毕业后，又有多少人与同学断了联系" >
	<meta name="keywords" content="留言" >
    <meta http-equiv="Cache-Control" content="no-cache,no-transform,no-siteapp" />
	<meta http-equiv="Pragma" content="no-cache" />	<meta http-equiv="Expires" content="0" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	
	
	<link href="images/t1-1.png" type="image/x-icon" rel="shortcut icon">
	
	<!--
	<link href="http://eput.com/favicon.ico" type="image/x-icon" rel="icon">
	<link href="http://eput.com/favicon.ico" type="image/x-icon" rel="shortcut icon">
	-->
	
	<link rel="stylesheet" type="text/css" href="css/style.css">
	<link rel="stylesheet" type="text/css" href="css/category_n.css">
	<link rel="stylesheet" type="text/css" href="css/head.css" >
	<link rel="stylesheet" type="text/css" href="css/style2.css">
	<script src="js/alert.js" type="text/javascript"></script>
  </head>
  
 <body  style="background-color:#eaeaea;">
<style>
	body{
		background:url(images/background.jpg) top left;
		background-size:100% 60%;
	}
</style>	
	
<style>

.navbar-global a {
color: #ccc;
}

.btn {
display: inline-block;
margin-bottom: 0;
font-weight: normal;
text-align: center;
vertical-align: middle;
cursor: pointer;
background-image: none;
border: 1px solid transparent;
white-space: nowrap;
padding: 6px 12px;
font-size: 14px;
line-height: 1.42857143;
border-radius: 4px;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}

.btn-header-border {
background: none;
color: #777;
border: 1px solid #555;
}
.btn-header {
padding: 0 .5em;
margin-left: .8em;
height: 30px;
line-height: 30px;
border: none;
background-color: #555;
display: inline-block;
border-radius: 2px;
}

.btn-header-border {
background: none;
color: #777;
border: 1px solid #555;
}
</style>	
	
<%@ include file="header.jsp" %>


	
<div class="container" style="margin-bottom:0px; ">
	
	<div id="cg_top">
		<div class="cg_head padding0">
			<div class="container">
				<div class="cont_wrap">
					<div style="float:left;">
					    <span style="color:red;" >在这里，记录了“我们”之间的点点滴滴</span>		
					</div>
					<div class="nav-search" style="margin-left:985px;">
					    <form action="message.jsp" method="get">
                           <input  type="text" placeholder="请输入姓名或账号" id="findmessage" name="findmessage" value="<%=text%>">
                           <button type="submit" class="btn btn-sm btn-primary" >搜索</button>
                        </form>
				   </div>
					<div class="hr_black" >
							<div class="button-holder" style="margin-top:10px; float:right">

							</div>
					</div>
				</div>
			</div>
		</div>
	</div>
<%@ page import= "java.sql.*"%>
<%@ page import= "com.connect.connect"%>	
<%
    connect conn =new connect();
	Connection con = conn.con();
	String sql="";
	int sum=0;
	if(text.equals("")){
        sql="SELECT * FROM message WHERE UserNumber='"+usernumber+"'";
    } else {
        sql="SELECT * FROM message WHERE UserNumber='"+usernumber+"' AND ToUserNumber='"+text+"' OR ToUserName='"+text+"'";
    }
    try{
		Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
	    ResultSet rs=stmt.executeQuery(sql);
	    while(rs.next()){
	        sum++;
	    }
	    con.close();
	}catch(SQLException e){
		e.printStackTrace();
    }	
    if(sum<=10){
        sum=0;
    } else {
        sum=sum-10;
    }
%>	
	
	


<img src="images/message.jpg" style="position:absolute;margin-left:100px; margin-top:5px;">
	
    <div class="activity_wrap" style="margin-top:42px;">								
        <div class="activity_one" style="background-image: url(images/mail.jpg); -webkit-transform: translate3d(0px, 0px, 0px); top: 0px; height:<%=377+sum*35 %>px;">
        	<div class="hr_black" >
				<div class="button-holder" style="margin-top:10px; float:right">

				</div>
			</div>

<%
	con = conn.con();
	String ToUserName;
	String ToUserNumber;
	String Time;
	String id="";
	String flag;
	if(text.equals("")){
        sql="SELECT * FROM message WHERE UserNumber='"+usernumber+"'";
    } else {
        sql="SELECT * FROM message WHERE UserNumber='"+usernumber+"' AND ToUserNumber='"+text+"' OR ToUserName='"+text+"'";
    }
    int i=0;
    	try{
		Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
	    ResultSet rs=stmt.executeQuery(sql);
	    while(rs.next()){
	        i++;
	        id = rs.getString("id");
	        flag = new String("2"+id);
	        ToUserNumber = rs.getString("ToUserNumber");
	        if(rs.getString("ToUserName").toString().equals("")){
	            ToUserName="(*未填写)";
	        } else {
	            ToUserName = rs.getString("ToUserName");
	        }
	        Time = rs.getString("Time");
%>
        <div style="margin-left:0px;width:1200px;">
        <div style="float:left;width:100px;">
        <span><center><%=i %><center></span>
        </div>
        <div style="float:left;width:320px;">
        <span"><center><%=ToUserNumber %></center></span>
        </div>
        <div style="float:left;width:410px;">
        <span><center><%=ToUserName %></center></span>
        </div>
        <div style="float:left;width:270px;">
        <span><center><%=Time %></center></span>
        </div>
        <div style="float:left;width:50px;">
        <center><a style="color:blue;font-size:15px;" href="message_other.jsp?flag=<%=flag%>"> 查看</a></center>
        </div>
        <div style="float:left;width:50px;">
        <center><a style="color:blue;font-size:15px;" href="delete_message.do?id=<%=id%>"> 删除</a></center>
        </div>
        </div>
        <div class="hr_black" style="float:left;">
				<div class="button-holder" style="padding-top:10px;">

				</div>
		</div>
<%
	    }
	    con.close();
	}catch(SQLException e){
		e.printStackTrace();
    }
%>   
            <%
                if(i!=0){
             %>
            <span style="color:red;font-size:16px;"><center>总共有<%=i %>条留言</center></span>
           <%
           } else{ 
           %>
           <div style="padding-top:150px;">
            <span style="color:;font-size:20px;"><center>你还没有给“他（她）”留言哦！快去<a style="color:blue"href="takemessage.jsp?tousername=" >留言</a></center></span>
            </div>
           <%} %>
	    </div>	
    </div>
</div>


<%@ include file="footer.jsp" %>

<!--[if lt IE 9]>
<iframe class="bc-warn" src="browsercheck.html" frameborder="0"></iframe>
<div class="bc-screen-lock"></div>
<link href="http://static.tuchong.net/styles/ie-checker.css?1435126808.css" rel="stylesheet" />
<![endif]-->
<div class="back-to-top direction-caret big"></div>

</body>
</html>
